var mainModule = angular.module('mainModule', [ 'ngResource', 'busServices', 'ngMaterial' ]);

mainModule.controller('SeatListCtrl', [ '$scope', '$mdDialog', 'Bus', function($scope, $mdDialog, Bus) {
	$scope.busses = {};
	
	$scope.busService = Bus.query({}, function() {
		
		$scope.busses = $scope.busService[0];

		$scope.currentBus = $scope.busses/* Non capisco il perché devo commentare ciò: [0] */;
		
		$scope.groupedSeats = [];

		var seats = $scope.currentBus.seats;
		
		for(seatIdx in seats) {
			var x = parseInt( seatIdx / 4 );
			var y = parseInt( seatIdx % 4 );
			
			if(typeof $scope.groupedSeats[x] === "undefined") {
				$scope.groupedSeats[x] = [];
			}
			
			var currentSeat = seats[seatIdx];
			
			$scope.groupedSeats[x][y] = currentSeat;
		}
		
	});
	
	$scope.showEditBooking = function(ev, seat) {

		$mdDialog.show({
			controller: DialogController,
			templateUrl: 'EditBooking.tmpl.html',
			targetEvent: ev,
		})
		.then(function(answer) {
			console.log("Success answer!");
		}, function() {
			console.log("Failed answer!");
		});
	
	};

	function DialogController($scope, $mdDialog) {
		$scope.hide = function() {
			$mdDialog.hide();
		};
		$scope.cancel = function() {
			$mdDialog.cancel();
		};
		$scope.answer = function(answer) {
			$mdDialog.hide(answer);
		};	
	}

}]);

mainModule.controller("SeatCtrl", function($scope, $mdDialog) {

	
//	$scope.doClick = function(seat) {
//    	bootbox.dialog({
//    		title: "Modifica prenotazione",
//    		message: '<div class="row">' +
//	    		'<div class="col-md-12">' +
//	    		'<form class="form-horizontal">' +
//	    		'<div class="form-group">' +
//	    		'<label class="col-md-4 control-label" for="firstName">Nome:</label>' +
//	    		'<div class="col-md-4">' +
//	    		'<input id="first-name-input" name="firstName" type="text" placeholder="Nome..." class="form-control input-md">' +
//	    		'</div>' +
//	    		'</div>' +
//	    		'<div class="form-group">' +
//	    		'<label class="col-md-4 control-label" for="lastName">Cognome:</label>' +
//	    		'<div class="col-md-4">' +
//	    		'<input id="last-name-input" name="lastName" type="text" placeholder="Cognome..." class="form-control input-md">' +
//	    		'</div>' +
//	    		'</div>' +
//	    		'<div class="form-group">' +
//	    		'<label class="col-md-4 control-label" for="phone">Telefono:</label>' +
//	    		'<div class="col-md-4">' +
//	    		'<input id="phone-input" name="phone" type="tel" placeholder="Telefono..." class="form-control input-md">' +
//	    		'</div>' +
//	    		'</div>' +
//	    		'</form>' +
//	    		'</div>' +
//	    		'</div>',
//	    	buttons: {
//	    		success: {
//	    			label: "Ok",
//	    			callback: function() {}
//	    		}
//	    	},
//	    	closeButton: false
//    	});
//		
//    }
	
});
